package com.site.wisdom_construction.controller.personnelModule;

import com.site.wisdom_construction.entity.personnelModule.ManagerialStaff;
import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.personnelModule.ManagerialStaffService;
import com.site.wisdom_construction.util.TimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/4
 * @Description
 */
@Api(tags = "管理人员接口")
@RestController
@RequestMapping("ManagerialStaff")
@CrossOrigin
public class ManagerialStaffController {
    @Autowired
    private ManagerialStaffService managerialStaffService;

    @ApiOperation(value = "增加管理人员信息", notes = "测试数据:")
    @PostMapping("/insertLabourEnterpriseApproach")
    public JsonResult insertManagerialStaff(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("entryDate", TimeUtils.getNowTime());
        List<ManagerialStaff> managerialStaffList = managerialStaffService.findManagerialStaffByPhone(map);
        if (managerialStaffList.size()>0){
            jsonResult.setCode(200);
            jsonResult.setMessage("管理人员已存在!");
        }else {
            int i = managerialStaffService.insertManagerialStaff(map);
            if (i==1){
                jsonResult.setCode(200);
                jsonResult.setMessage("成功录入管理人员信息!");
            }else {
                jsonResult.setCode(20006);
                jsonResult.setMessage("录入管理人员信息失败!");
            }
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除管理人员信息", notes = "测试数据:")
    @PostMapping("/deleteManagerialStaff")
    public JsonResult deleteManagerialStaff(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = managerialStaffService.deleteManagerialStaff(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除管理人员信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除管理人员信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改管理人员信息", notes = "测试数据:")
    @PostMapping("/updateManagerialStaff")
    public JsonResult updateManagerialStaff(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = managerialStaffService.updateManagerialStaff(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改管理人员信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改管理人员信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "管理人员进场", notes = "测试数据:")
    @PostMapping("/updateManagerialStaffByStatusJ")
    public JsonResult updateManagerialStaffByStatusJ(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("entryDate",TimeUtils.getNowTime());
        int i = managerialStaffService.updateManagerialStaffByStatusJ(map);
        if(i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("管理人员进场成功!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("管理人员进场失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "管理人员离场", notes = "测试数据:")
    @PostMapping("/updateManagerialStaffByStatusT")
    public JsonResult updateManagerialStaffByStatusT(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("leaveDate",TimeUtils.getNowTime());
        int i = managerialStaffService.updateManagerialStaffByStatusT(map);
        if(i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("管理人员离场成功!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("管理人员离场失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询管理人员信息", notes = "测试数据:")
    @PostMapping("/findManagerialStaffByPage")
    public Page findManagerialStaffByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(managerialStaffService.Total(map));
        page.setItems(managerialStaffService.findManagerialStaffByPage(map));
        return page;
    }

    @ApiOperation(value = "根据id查询管理人员信息", notes = "测试数据:")
    @PostMapping("/findManagerialStaffById")
    public OneDataResult findManagerialStaffById(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(managerialStaffService.findManagerialStaffById(map));
        return oneDataResult;
    }
}
